import com.fasterxml.jackson.databind.ObjectMapper;
import model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//模拟json发送http请求
@WebServlet("/json")
public class JsonServlet extends HttpServlet {

     private ObjectMapper objectMapper=new ObjectMapper();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("text/html;charset=utf-8");
        User user= objectMapper.readValue(req.getInputStream(),User.class);
        resp.getWriter().write("名字："+user.getName()+"年龄："+user.getAge());

    }
}
